<script setup lang="ts">
import { userChannelStore } from "@/stores/channel";
import type { AxiosResData, ChannelItem, ChannelResData } from "@/types";
import axios from "axios";
import { onMounted, ref } from "vue";

// defineProps<{
//   channelId: number;
// }>();

// defineEmits<{
//   "upData:channelId": [ChannelId: number];
// }>();

const store = userChannelStore()


const list = ref<ChannelItem[]>([]);

const getData = async () => {
  const res = await axios.get<AxiosResData<ChannelResData>>(
    "http://geek.itheima.net/v1_0/channels"
  );
  console.log(res);
  list.value = res.data.data.channels;
};

// 组件挂载完成
onMounted(() => {
  getData();
});
</script>

<template>
  <div class="channel-nav">
    <nav class="list">
      <a
        v-for="(item, i) in list"
        :key="item.id"
        class="item"
        :class="{ active: store.channelId === item.id }"
        href="javascript:;"
        @click="store.upDataChangelId(item.id)"
      >
        {{ item.name }}
      </a>
    </nav>
  </div>
</template>
